import axios, { DownExcel } from '@iframe/tools/axios/axios.js'
import dayjs from 'dayjs'

/**
 * 查询告警信息
 * @param params
 */
export function query(params) {
    return axios.request({
        url: `/${import.meta.env.IFRAME_CONTEXT_PATH}/alarm/details`,
        method: 'get',
        params: {
            status: params.status,
            beginTime: params.time && params.time.length > 0 ? dayjs(params.time[0]).format('YYYY-MM-DD HH:mm:ss') : null,
            endTime: params.time && params.time.length > 1 ? dayjs(params.time[1]).format('YYYY-MM-DD HH:mm:ss') : null,
            pageNo: params.pageNo,
            pageNum: params.pageNum
        }
    })
}

export function download(params) {
    axios
        .request({
            url: `/${import.meta.env.IFRAME_CONTEXT_PATH}/alarm/details/download`,
            method: 'get',
            params: {
                status: params.status,
                beginTime: params.time && params.time.length > 0 ? dayjs(params.time[0]).format('YYYY-MM-DD HH:mm:ss') : null,
                endTime: params.time && params.time.length > 1 ? dayjs(params.time[1]).format('YYYY-MM-DD HH:mm:ss') : null,
                pageNo: params.pageNo,
                pageNum: params.pageNum
            },
            responseType: 'blob'
        })
        .then(response => {
            DownExcel(response)
        })
}
